package com.example.coursehub.entity;

import lombok.NoArgsConstructor;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "favorite_question_bank_question", schema = "courseHub")
@NoArgsConstructor
public class FavoriteQuestionBankQuestion {
    @EmbeddedId
    private FavoriteQuestionBankQuestionId id;

    @MapsId("favoriteQuestionBankId")
    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "favorite_question_bank_id", nullable = false)
    private FavoriteQuestionBank favoriteQuestionBank;

    @MapsId("questionId")
    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "question_id", nullable = false)
    private Question question;
    public String getQuestionId() {
        return this.id != null ? this.id.getQuestionId() : null;
    }
    public FavoriteQuestionBankQuestion(FavoriteQuestionBankQuestionId id, FavoriteQuestionBank favoriteQuestionBank, Question question) {
        this.id = id;
        this.favoriteQuestionBank = favoriteQuestionBank;
        this.question = question;
    }
}